package logic

import (
	"context"
	"house/models/mysql"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AppAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAppAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppAddLogic {
	return &AppAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AppAddLogic) AppAdd(in *houserpc.AppAddRequest) (*houserpc.AppAddResponse, error) {
	// todo: add your logic here and delete this line

	app := mysql.App{
		AppName: in.AppName,
		UserId:  int(in.UserId),
		HouseId: int(in.HouseId),
	}
	mysql.DB.Debug().Create(&app)

	return &houserpc.AppAddResponse{
		AppId: int64(app.ID),
	}, nil
}
